#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import sys
sys.path.append('..')

from testdata import datas, keys_locates, locates, kc, level
from pro.stability_analysis import cal_weight, cal_factors, earthquake, cal_equation
from math import atan
locates['alpha1'] = atan((locates['yc'] - locates['yd']) / (locates['xc'] - locates['xd']))
locates['alpha2'] = atan((locates['yd'] - locates['ya']) / (locates['xd'] - locates['xa']))
print('计算时各点坐标为：')
for i in range(len(keys_locates)):
    print('%6s %8.4f ' % (keys_locates[i], locates[keys_locates[i]]), end = '')
    if i % 2 == 1:
        print()
weights = cal_weight(datas, locates)
print('    W1 %8.2f     W2 %8.2f' % weights)
if level == 0:
    factors = cal_factors(datas, locates, weights)
else:
    forces = earthquake(datas, locates, weights, level)
    factors = cal_factors(datas, locates, weights, forces[0], forces[1])
print('a = %6.2f, b = %6.2f, c = %6.2f' % factors)
result = cal_equation(factors[0], factors[1], factors[2])
print('Kc = %10.8f' % result[0])
